<template>
  <div class="user-container">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div>
              <el-avatar :size="100" :src="require('@/assets/avatar/avatar.png')" class="user-avatar" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="name" />用户名称
                <div class="pull-right">{{ user.name }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.phone }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="sex" />性别
                <div class="pull-right">{{ user.sex ? '女':'男' }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="dept" />部门
                <div class="pull-right">{{ user.dept }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="16">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>完善信息</span>
          </div>
          <div>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="完善资料" name="userinfo">
                <UserInfo />
              </el-tab-pane>
              <el-tab-pane label="修改密码" name="resetPwd">
                <ResetPwd />
              </el-tab-pane>
            </el-tabs>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getInfo } from '@/api/user'
import ResetPwd from '@/views/user/ResetPwd'
import UserInfo from '@/views/user/UserInfo'

export default {
  components: {
    ResetPwd,
    UserInfo
  },

  data() {
    return {
      user: {},
      activeTab: 'userinfo'
    }
  },

  created() {
    this.fetchData()
  },

  methods: {

    fetchData() {
      getInfo().then(response => {
        this.user = response.data
        this.user.dept = this.user.dept.dept_name
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.user-container {
  width: 100%;
  padding: 0 300px;
  margin-top: 20px;
  min-height: calc(100vh - 50px);

  .user-avatar {
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    border: 1px solid #4cd7e8;
  }

  .list-group {
    padding-left: 0;
    list-style: none;
  }

  .list-group-item {
    border-bottom: 1px solid #e7eaec;
    border-top: 1px solid #e7eaec;
    margin-bottom: -1px;
    padding: 11px 0;
    font-size: 15px;
  }

  .pull-right {
    float: right !important;
  }
}
</style>
